package day.day7_3;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            int a=sc.nextInt();
            int num=0;
            int first=0;
            int second=1;
            while (second<=a){
                num=first+second;
                first=second;
                second=num;
            }
            System.out.println(Math.min((second-a),(a-first)));
        }
    }
}
